/*
 * usr_wifi232_a.h
 * Project: wifi_module_code
 * Created on: Apr 5, 2013
 * Author: vagabond
 */

#ifndef USR_WIFI232_A_H_
#define USR_WIFI232_A_H_
/**
 * @brief use EVAL_COM2 to communication with wifi module(usr-wifi232-A)
 */

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/

#define USER_TIMEOUT                    ((uint32_t)0x64) /* Waiting 1s */

/* USART Mode Selected */
#define USART_MODE_TRANSMITTER           0x00
#define USART_MODE_RECEIVER              0x01

/* USART Transaction Type */
#define USART_TRANSACTIONTYPE_CMD        0x00
#define USART_TRANSACTIONTYPE_DATA       0x01


/* Definition for USARTWIFI resources ********************************************/
#define USARTWIFI                           USART3
#define USARTWIFI_CLK                       RCC_APB1Periph_USART3
#define USARTWIFI_CLK_INIT                  RCC_APB1PeriphClockCmd
#define USARTWIFI_IRQn                      USART3_IRQn
#define USARTWIFI_IRQHandler                USART3_IRQHandler

#define USARTWIFI_TX_PIN                    GPIO_Pin_10
#define USARTWIFI_TX_GPIO_PORT              GPIOC
#define USARTWIFI_TX_GPIO_CLK               RCC_AHB1Periph_GPIOC
#define USARTWIFI_TX_SOURCE                 GPIO_PinSource10
#define USARTWIFI_TX_AF                     GPIO_AF_USART3

#define USARTWIFI_RX_PIN                    GPIO_Pin_11
#define USARTWIFI_RX_GPIO_PORT              GPIOC
#define USARTWIFI_RX_GPIO_CLK               RCC_AHB1Periph_GPIOC
#define USARTWIFI_RX_SOURCE                 GPIO_PinSource11
#define USARTWIFI_RX_AF                     GPIO_AF_USART3

/* Echo mode */
#define ECHO								1

/* Define reset pin */
#define WIFIRESET_GPIO_PIN                    GPIO_Pin_9
#define WIFIRESET_GPIO_PORT                   GPIOC
#define WIFIRESET_GPIO_CLK                    RCC_AHB1Periph_GPIOC

/* Define transmission mode */

#define TRANSPARENT_TRANSMISSION			0x00
#define AGREEMENT_TRANSMISSION				0x01


/* Exported variables --------------------------------------------------------*/


/* Exported functions ------------------------------------------------------- */
void WifiConfiguration(void);
uint8_t activeModule(void);
uint8_t setSTAMode(int8_t apSSSID[], int8_t auth[], int8_t encry[], int8_t keySercurity[]);
uint8_t getIPaddress(int8_t ipAddress[]);
uint8_t connectServer(int8_t serverIPAddress[], int8_t portNum[]); //as client
uint8_t Listen(int8_t serverIPAddress[], int8_t portNum[]); //as server

void sendDataTransparentMode(char data[], char ipAddress[]);
void getDataTransparentMode(int8_t data[], int8_t ipAddress[]);

uint8_t setTransmissionMode(int8_t mode);
void restart();
int bufferLength();
#endif /* USR_WIFI232_A_H_ */
